package com.viki.test.testvisitinternet;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class MainActivity extends ListActivity {
	private Map<String, Intent> mItemMap = new LinkedHashMap<String, Intent>();
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initItemMap();
        setListAdapter(new SimpleAdapter(this, getData(), android.R.layout.simple_list_item_1, new String[] { "title" }, new int[] { android.R.id.text1 }));
    }
    private List<Map<String, Object>> getData() {
    	List<Map<String, Object>> listData = new ArrayList<Map<String, Object>>();
    	for(HashMap.Entry<String, Intent> it : mItemMap.entrySet()) {
    		Map<String,Object> itemMap = new HashMap<String,Object>();
    		itemMap.put("title",it.getKey());
      	    itemMap.put("intent",it.getValue());
      	    listData.add(itemMap);
    	}
    	return listData;
    }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        Map<?, ?> map = (Map<?, ?>) l.getItemAtPosition(position);
        Intent intent = (Intent) map.get("intent");
        startActivity(intent);
    }
    private void initItemMap() {
    	mItemMap.put("1.simulate sina weibo", new Intent(MainActivity.this, SimulateWeiboActivity.class));
    	mItemMap.put("2.visit https with authority", new Intent(MainActivity.this, AccessHttpsWithAuthorityActivity.class));
    }
}